package com.plian.system.task.message;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.plian.Tools.CollectionUtil;
import com.plian.system.entity.sys.Message;
import com.plian.system.enumeratea.FormTableEnum;
import com.plian.system.service.cqzc.bondissue.BondsIssueService;
import com.plian.system.service.pf.IBaseGrantSalaryService;
import com.plian.system.service.sys.message.IMessageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.List;

/**
 * @description: 首页消息列表
 * @author: gangan
 * @create: 2020-01-13
 */
@Configuration
public class MessageTask {

    private static final Logger log = LoggerFactory.getLogger(MessageTask.class);

    @Autowired
    private BondsIssueService bondissueService;

    @Autowired
    private IMessageService messageService;

    @Autowired
    private IBaseGrantSalaryService baseGrantSalaryService;


    /**
     * 债券发行  到期消息生成
     */
    @Scheduled(cron = "0 0 1 * * ?")
    private void bondTasks() {
        List<Message> messages = bondissueService.noRepaymentList();
        messageService.remove(new QueryWrapper<Message>()
                .eq("form_type", "" + FormTableEnum.CQZC_BONDISSUE.getFormType()));
        if (CollectionUtil.isNotEmpty(messages)){
            messageService.saveBatch(messages);
        }
    }

    /**
     * 工资发放管理 超过预警线信息生成
     */
    @Scheduled(cron = "0 0 1 * * ?")
    private void salaryTasks() {
        List<Message> messages = baseGrantSalaryService.getWarningMessage();
        messageService.remove(new QueryWrapper<Message>()
                .eq("form_type", "salaryWarning"));
        if (CollectionUtil.isNotEmpty(messages)){
            messageService.saveBatch(messages);
        }
    }



    public void start(){
        bondTasks();
        salaryTasks();
    }
}
